# 使用事项：1、记得设置VXPUSH_TOKEN的环境变量

#coding=utf-8
import os
import requests,json
import logging


env_dist = os.environ
 
def pushToWechartText(message_data):
    result = {'result':False}
    url = 'http://wxpusher.zjiecode.com/api/send/message'
    data = {
    "appToken": env_dist.get('VXPUSH_TOKEN'),
    "content":message_data,
    "contentType":1,
    "topicIds":[ 
        165
    ],
    "uids":[
        "UID_9RKJJaStGYAXkzmpURXQKYZJb7OF"
    ],
    "url":"http://wxpusher.zjiecode.com"
    }
    try:
        r = requests.post(url,json=data)
        #     print(r.text)
        recJson = json.loads(r.text)
        if recJson['success'] == True:
            result['result'] = True
            result['data'] = recJson
            return result
        else :
            result['data'] = r.text
            return result
    except Exception as e:
        result['data'] = e
        return result

def pushToWechartHtml(message_data):
    result = {'result':False}
    url = 'http://wxpusher.zjiecode.com/api/send/message'
    data = {
    "appToken": env_dist.get('VXPUSH_TOKEN'),
    "content":message_data,
    "contentType":2,
    "topicIds":[ 
        165
    ],
    "uids":[
        "UID_9RKJJaStGYAXkzmpURXQKYZJb7OF"
    ],
    "url":"http://wxpusher.zjiecode.com"
    }
    try:
        r = requests.post(url,json=data)
        #     print(r.text)
        recJson = json.loads(r.text)
        if recJson['success'] == True:
            result['result'] = True
            result['data'] = recJson
            return result
        else :
            result['data'] = r.text
            return result
    except Exception as e:
        result['data'] = e
        return result

    
